class Solution(object):
    def numSubseq(self, nums, target):
        nums.sort()
        left = 0
        n = len(nums)
        right = n - 1
        ans = 0
        base = 10 ** 9 + 7
        while left <= right:
            if nums[left] + nums[right] <= target:
                ans = (ans + pow(2, right - left, base)) % base
                left += 1
            else:
                right -= 1
        return ans
